#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void nextPermutation(int* nums, int numsSize);
void swap(int* restrict o1, int* restrict o2);

int main()
{
	return 0;
}

void nextPermutation(int* nums, int numsSize)
{
	int minIdx = -1, maxIdx = numsSize - 1;
	for (int i = numsSize - 1; i > 0; i--)
		if (nums[i - 1] < nums[i]) {minIdx = i - 1; break;}
	if (minIdx != -1) {
        //printf("minIdx:%d\t", nums[minIdx]);
		for (int i = numsSize - 1; i > minIdx; i--)
			if (nums[i] > nums[minIdx]) {maxIdx = i; break;}
        //printf("maxIdx:%d\t", nums[maxIdx]);
		swap(nums + minIdx, nums + maxIdx);
	}

	int startIdx = minIdx + 1, endIdx = numsSize - 1;
	while (startIdx < endIdx)
		swap(nums + startIdx++, nums + endIdx--);
}

void swap(int* o1, int* o2)
{
	int tmp = *o1;
	*o1 = *o2;
	*o2 = tmp;
}